<template>
	<view class="school_content">

		<view class="card" v-for="(item,index) in list" :key="index" @click="toschoolequipementinfo(item)">

			<view class="name" @click="toschoolequipementinfo(item)"> {{item.name}}</view>

		</view>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				list: [],
				id: 0,
				page: 0,
				nodatastatus: 0,
			}
		},
		onLoad() {
			this.getbookingList(0, 0);
		},
		methods: {
			getbookingList: function(id, page) {


				page = page + 1;
				const that = this;
				let nodatastatus = this.nodatastatus;
				if (nodatastatus == 1) return;

				uni.showLoading({
					title: '加载中...',
				})

				this.$request.request('api/equipment/list?id=' + id + '&page=' + page + '&token=' + wx.getStorageSync(
					'token'), '', 0, 'get', false).then(res => {
					let res2w = res.data;
					if (typeof res2w == 'string') {
						let str22 = res2w.replace(/\ufeff/g, ""); //去除反斜杠
						res2w = JSON.parse(str22); //string转object
					}
					console.log('res2w=', res2w)
					if (res2w.status == 1) {
						const res2_data_data = res2w.data;
						let list = res2w.data.list;
						let datalist = that.list;


						if (!list) list = [];
						if (list.length == 0) nodatastatus = 1;
						let lastid = 0;
						list.forEach((item, index) => {
							lastid = item.id;
							datalist.push(item);
						})

						that.list = datalist
						that.page = page
						that.id = lastid
						that.nodatastatus = nodatastatus

					} else if (res2w.status == -2) {

						uni.showToast({
							title: "" + res2w.msg,
							icon: 'none',
							duration: 3000,
							success: function() {

							}
						});
						uni.removeStorageSync('token');
						uni.removeStorageSync('isuser');

						setTimeout(() => {
							uni.redirectTo({
								url: '../login/login?redirect_page=equipmentlist',
							})
						}, 3000);

					} else {


						uni.showToast({
							title: "" + res2w.msg,
							icon: 'none',
							duration: 3000
						});


					}

					uni.hideLoading();

				})

			},

			onReachBottom() {
				this.list = [],
					this.id = 0,
					this.page = 0,
					this.nodatastatus = 0,
					this.getbookingList(0, 0);
			},
			onPullDownRefresh() {
				this.getbookingList(this.id, this.page + 1);
			},
			toschoolequipementinfo(item) {
				console.log('toschoolequipementinfo----',item)
				uni.navigateTo({
					url: '/pages/school/equipementinfo/index?id='+item.id
				})
			}
		}
	}
</script>

<style>
	page {}

	.school_content {
		display: flex;
		flex-direction: column;

		font-size: 16px;
	}

	.card {
		display: flex;
		flex-direction: column;
		border: 0px solid #d2d2d2;
		padding: 10px 10px;
		margin: 5px 0px;
		background-color: white;

	}
</style>